class YLCountDownUtil {
  ///补零
  static String zeroFill(int value) {
    return value >= 10 ? '$value' : '0$value';
  }

  /// 秒转分秒
  static String secondToMS(int sec, {bool isEasy = true}) {
    String hms = "00:00";
    if (!isEasy) hms = "00分00秒";
    if (sec > 0) {
      int m = sec ~/ 60;
      // int m = (sec % 3600) ~/ 60;
      int s = sec % 60;
      hms = "${zeroFill(m)}:${zeroFill(s)}";
      if (!isEasy) hms = "${zeroFill(m)}分${zeroFill(s)}秒";
    }
    return hms;
  }

  /// 秒转时分秒
  static String secondToHMS(int sec, {bool isEasy = true}) {
    String hms = "00:00:00";
    if (!isEasy) hms = "00时00分00秒";
    if (sec > 0) {
      int h = sec ~/ 3600;
      int m = (sec % 3600) ~/ 60;
      int s = sec % 60;
      if (h > 0) {
        hms = "${zeroFill(h)}:${zeroFill(m)}:${zeroFill(s)}";
        if (!isEasy) hms = "${zeroFill(h)}时${zeroFill(m)}分${zeroFill(s)}秒";
      } else {
        hms = "${zeroFill(m)}:${zeroFill(s)}";
        if (!isEasy) hms = "${zeroFill(m)}分${zeroFill(s)}秒";
      }
    }
    return hms;
  }

  /// 秒转天时分秒
  static String secondToDHMS(int sec, {bool isEasy = true}) {
    String hms = "00 00:00:00";
    if (!isEasy) hms = "00天00时00分00秒";
    if (sec > 0) {
      int d = sec ~/ 86400;
      int h = (sec % 86400) ~/ 3600;
      int m = (sec % 3600) ~/ 60;
      int s = sec % 60;

      if (d > 0) {
        hms = "${zeroFill(d)} ${zeroFill(h)}:${zeroFill(m)}:${zeroFill(s)}";
        if (!isEasy) {
          hms = "${zeroFill(d)}天${zeroFill(h)}时${zeroFill(m)}分${zeroFill(s)}秒";
        }
      } else if (h > 0) {
        hms = "${zeroFill(h)}:${zeroFill(m)}:${zeroFill(s)}";
        if (!isEasy) hms = "${zeroFill(h)}时${zeroFill(m)}分${zeroFill(s)}秒";
      } else {
        hms = "${zeroFill(m)}:${zeroFill(s)}";
        if (!isEasy) hms = "${zeroFill(m)}分${zeroFill(s)}秒";
      }
    }
    return hms;
  }

  /// 秒转天时分秒
  /// type 0 分秒  type 1 时分秒 type 2日时分秒
  static List<int> secondToList(int sec, {int type = 2}) {
    List<int> list = [];
    if (type == 2) {
      int d = sec ~/ 86400;
      int h = (sec % 86400) ~/ 3600;
      int m = (sec % 3600) ~/ 60;
      int s = sec % 60;

      list = [d, h, m, s];
    } else if (type == 1) {
      // int d = sec ~/ 86400;
      int h = sec ~/ 3600;
      int m = (sec % 3600) ~/ 60;
      int s = sec % 60;

      list = [h, m, s];
    } else {
      int m = sec ~/ 60;
      int s = sec % 60;
      list = [m, s];
    }
    return list;
  }

  //获取当前是今天的多少秒
  static int currentTimeToSecond() {
    DateTime nowTime = DateTime.now();
    int second = nowTime.second + nowTime.minute * 60 + nowTime.hour * 3600;
    return second;
  }
}
